home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWBmpShp.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.1 KB  |  248 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWBmpShp.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWBMPSHP_H
  13. #include "FWBmpShp.h"
  14. #endif
  15.  
  16. #ifndef FWGRGLOB_H
  17. #include "FWGrGlob.h"
  18. #endif
  19.  
  20. #ifndef FWGC_H
  21. #include "FWGC.h"
  22. #endif
  23.  
  24. #ifndef FWFXMATH_H
  25. #include "FWFxMath.h"
  26. #endif
  27.  
  28. #ifndef FWRASTER_H
  29. #include "FWRaster.h"
  30. #endif
  31.  
  32. // ----- Foundation Includes -----
  33.  
  34. #ifndef FWSTREAM_H
  35. #include "FWStream.h"
  36. #endif
  37.  
  38. #ifndef FWDEBUG_H
  39. #include "FWDebug.h"
  40. #endif
  41.  
  42. //========================================================================================
  43. //    RunTime Info
  44. //========================================================================================
  45.  
  46. #if FW_LIB_EXPORT_PRAGMAS
  47. #pragma lib_export on
  48. #endif
  49.  
  50. #ifdef FW_BUILD_MAC
  51. #pragma segment fwgraphxshape
  52. #endif
  53.  
  54. FW_DEFINE_CLASS_M1(FW_CBitmapShape, FW_CBoundedShape)
  55.  
  56. FW_REGISTER_ARCHIVABLE_CLASS(FW_LBitmapShape, FW_CBitmapShape, FW_CBitmapShape::Read, FW_CShape::Write)
  57.  
  58. //========================================================================================
  59. //    CLASS FW_CBitmapShape
  60. //========================================================================================
  61.  
  62. //----------------------------------------------------------------------------------------
  63. //    FW_CBitmapShape::FW_CBitmapShape
  64. //----------------------------------------------------------------------------------------
  65.  
  66. FW_CBitmapShape::FW_CBitmapShape(const FW_CBitmapShape& other) :
  67.     FW_CBoundedShape(other),
  68.     fSrcRect(other.fSrcRect),
  69.     fBitmap(other.fBitmap)
  70. {
  71.     FW_END_CONSTRUCTOR
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------
  75. //    FW_CBitmapShape::FW_CBitmapShape
  76. //----------------------------------------------------------------------------------------
  77.  
  78. FW_CBitmapShape::FW_CBitmapShape(FW_PBitmap bitmap, const FW_CRect& dstRect) :
  79.     FW_CBoundedShape(dstRect, FW_kFill, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  80.     fBitmap(bitmap)
  81. {
  82.     short width, height,rowBytes, pixelSize;
  83.     fBitmap->GetBitmapInfo(width, height, rowBytes, pixelSize);
  84.     fSrcRect.SetInt(0, 0, width, height);
  85.  
  86.     FW_END_CONSTRUCTOR
  87. }
  88.  
  89. //----------------------------------------------------------------------------------------
  90. //    FW_CBitmapShape::FW_CBitmapShape
  91. //----------------------------------------------------------------------------------------
  92.  
  93. FW_CBitmapShape::FW_CBitmapShape(FW_PBitmap bitmap, const FW_CRect& srcRect, const FW_CRect& dstRect) :
  94.     FW_CBoundedShape(dstRect, FW_kFill, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  95.     fSrcRect(srcRect),
  96.     fBitmap(bitmap)
  97. {
  98.     FW_END_CONSTRUCTOR
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. //    FW_CBitmapShape::FW_CBitmapShape
  103. //----------------------------------------------------------------------------------------
  104.  
  105. FW_CBitmapShape::FW_CBitmapShape(FW_CReadableStream& archive) :
  106.     FW_CBoundedShape(archive)
  107. {
  108.     archive.Read(&fSrcRect, 4);
  109.     archive >> fBitmap;
  110.     
  111.     FW_END_CONSTRUCTOR
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    FW_CBitmapShape::~FW_CBitmapShape
  116. //----------------------------------------------------------------------------------------
  117.  
  118. FW_CBitmapShape::~FW_CBitmapShape()
  119. {
  120.     FW_START_DESTRUCTOR
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    FW_CBitmapShape::operator=
  125. //----------------------------------------------------------------------------------------
  126.  
  127. FW_CBitmapShape& FW_CBitmapShape::operator=(const FW_CBitmapShape& other)
  128. {
  129.     if (this != &other)
  130.     {
  131.         FW_CBoundedShape::operator=(other);
  132.         
  133.         fBitmap = other.fBitmap;
  134.         fSrcRect = other.fSrcRect;
  135.     }
  136.     
  137.     return *this;
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CBitmapShape::Copy
  142. //----------------------------------------------------------------------------------------
  143.  
  144. FW_CShape* FW_CBitmapShape::Copy() const
  145. {
  146.     return FW_NEW(FW_CBitmapShape, (*this));
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. //    FW_CBitmapShape::Render
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void FW_CBitmapShape::Render(FW_CGraphicContext& gc) const
  154. {
  155.     gc.GetRasterizer()->RenderBitmap(gc,
  156.                                     fBitmap,
  157.                                     fSrcRect,
  158.                                     fRect,
  159.                                     GetRenderVerb(),
  160.                                     fInk);
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    FW_CBitmapShape::RenderBitmap
  165. //----------------------------------------------------------------------------------------
  166.  
  167. void FW_CBitmapShape::RenderBitmap(FW_CGraphicContext& gc,
  168.                                     FW_PBitmap bitmap,
  169.                                     const FW_CRect& dstRect,
  170.                                     const FW_PInk& ink)
  171. {
  172.     FW_CRect srcRect;
  173.     bitmap->GetBitmapBounds(srcRect);
  174.  
  175.     gc.GetRasterizer()->RenderBitmap(gc,
  176.                                     bitmap,
  177.                                     srcRect,
  178.                                     dstRect,
  179.                                     FW_kFill,
  180.                                     ink);
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    FW_CBitmapShape::RenderBitmap
  185. //----------------------------------------------------------------------------------------
  186.  
  187. void FW_CBitmapShape::RenderBitmap(FW_CGraphicContext& gc,
  188.                                     FW_PBitmap bitmap,
  189.                                     const FW_CRect& srcRect, 
  190.                                     const FW_CRect& dstRect,
  191.                                     const FW_PInk& ink)
  192. {
  193.     gc.GetRasterizer()->RenderBitmap(gc,
  194.                                     bitmap,
  195.                                     srcRect,
  196.                                     dstRect,
  197.                                     FW_kFill,
  198.                                     ink);
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    FW_CBitmapShape::GetGeometry
  203. //----------------------------------------------------------------------------------------
  204.  
  205. void FW_CBitmapShape::GetGeometry(FW_PBitmap& bitmap, 
  206.                                 FW_CRect& srcRect, 
  207.                                 FW_CRect& dstRect) const
  208. {
  209.     bitmap = fBitmap;
  210.     srcRect = fSrcRect;
  211.     dstRect = fRect;
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. //    FW_CBitmapShape::SetGeometry
  216. //----------------------------------------------------------------------------------------
  217.  
  218. void FW_CBitmapShape::SetGeometry(const FW_PBitmap& bitmap, 
  219.                                 const FW_CRect& srcRect, 
  220.                                 const FW_CRect& dstRect)
  221. {
  222.     fBitmap = bitmap;
  223.     fSrcRect = srcRect;
  224.     fRect = dstRect;
  225. }
  226.  
  227. //----------------------------------------------------------------------------------------
  228. //    FW_CBitmapShape::Flatten
  229. //----------------------------------------------------------------------------------------
  230.  
  231. void FW_CBitmapShape::Flatten(FW_CWritableStream& archive) const
  232. {
  233.     FW_CBoundedShape::Flatten(archive);
  234.     archive.Write(&fSrcRect, 4);
  235.     fBitmap->Flatten(archive);
  236. }
  237.  
  238. //----------------------------------------------------------------------------------------
  239. //    FW_CBitmapShape::Read
  240. //----------------------------------------------------------------------------------------
  241.  
  242. void* FW_CBitmapShape::Read(FW_CReadableStream& archive)
  243. {
  244.     FW_CBitmapShape* object = FW_NEW(FW_CBitmapShape, (archive));
  245.     return object;
  246. }
  247.  
  248.